<?php
session_start();
//Set timezone for log info.
//Grab the two salts from previous page, student hash, and student info.
date_default_timezone_set("America/New_York");
include("../hacs_control/password_control/pass_grab.php");
$salt1 = $_POST["salt1"];
$salt2 = $_POST["salt2"];
$student = $_POST["student"];
$class = $_POST["classCall"];
$str=grab_pass($student,$class);
$str=trim($str);
//Serverside hash of the actual password
//Check against the student's hash value
$result = hash_hmac('md5', $str , $_POST["salt1"]);
$result = hash_hmac('md5', $result, $_POST["salt2"]);
$check = $_POST["check"];
//If they match, set all the session variables
//that are going to be needed in future pages.
if(strcmp($result,$_POST["check"]) == 0){
	$_SESSION['loggedIn']=1;
	$_SESSION['student']=$student;
	$_SESSION['class']=$class;
	$file="../data/Logs/login_log.txt";
	//Log the login using timestamp and IP address
	$timestamp=date('m-d-Y h:i:s a', time());
	$ip=$_SERVER['REMOTE_ADDR'];
	$str2=$timestamp . ", " . $class . ", " . $student . ", " . $ip;
	file_put_contents($file, $str2 . "\n", FILE_APPEND);
	header('Location: StudentAssignment.php');
}else{
//if Fail, return to login screen, and set failure variable.
	$_SESSION['failed']=0;
	header('Location: StudentLogin.php');
}
?>